import pycurl, json, StringIO, sys, time, Queue
from twisted.protocols import amp
	
tweetQueue = Queue.Queue()

class GetTweet(amp.Command):
	arguments = []
	response = [('tweet', amp.Integer())]

class StoreTweet(amp.Command):
	arguments = [('data', amp.String())]
	response = []

class TweetographerProtocol(amp.AMP):
	def getTweet(self):
		print "Request"
		return {'tweet': tweetQueue.get()}
	GetTweet.responder(getTweet)
	
	def storeTweet(self,data):
		print "Recieved data."
		tweetQueue.put(data)
	StoreTweet.responder(storeTweet)
		

def main():
    from twisted.internet import reactor
    from twisted.internet.protocol import Factory
    pf = Factory()
    pf.protocol = TweetographerProtocol
    reactor.listenTCP(1234, pf)
    print 'Started'
    reactor.run()

if __name__ == '__main__':
    main()
